package dubrouski.segmentation;

/**
 *
 * @author Stanislau Dubrouski
 */
public class SeedsStack {

    private int maxStackSize = 500; // will be increased as needed
    private int[] xStack;
    private int[] yStack;
    private int[] zStack;
    private int stackSize;

    public SeedsStack(int stackSize) {
        this.maxStackSize = stackSize;
        this.xStack = new int[maxStackSize];
        this.yStack = new int[maxStackSize];
        this.zStack = new int[maxStackSize];
        this.stackSize = 0;
    }

    public void push(int x, int y, int z) {
        stackSize++;
        if (stackSize == maxStackSize) {
            int[] newXStack = new int[maxStackSize * 2];
            int[] newYStack = new int[maxStackSize * 2];
            int[] newZStack = new int[maxStackSize * 2];
            System.arraycopy(xStack, 0, newXStack, 0, maxStackSize);
            System.arraycopy(yStack, 0, newYStack, 0, maxStackSize);
            System.arraycopy(zStack, 0, newZStack, 0, maxStackSize);
            xStack = newXStack;
            yStack = newYStack;
            zStack = newZStack;
            maxStackSize *= 2;
        }
        xStack[stackSize - 1] = x;
        yStack[stackSize - 1] = y;
        zStack[stackSize - 1] = z;
    }

    public int popX() {
        if (stackSize == 0) {
            return -1;
        } else {
            return xStack[stackSize - 1];
        }
    }

    public int popY() {
        int value = yStack[stackSize - 1];
        return value;
    }

    public int popZ() {
        int value = zStack[stackSize - 1];
        stackSize--;
        return value;
    }
}